package org.happen.android.core.data;

import java.io.File;

import org.happen.android.app.AppContext;
import org.happen.android.app.Globals;
import org.happen.android.app.ILife;
import org.happen.android.core.data.image.ImageCacheManager;
import org.liushui.mycommons.android.log.McLog;

public class DataCache implements ILife
{
	private static DataCache instance;

	public static DataCache getInstance()
	{
		if (instance == null)
		{
			McLog.md(DataCache.class, "getInstance");
			instance = new DataCache();
		}
		return instance;
	}

	AppInfo appConfig;

	private DataCache()
	{
		appConfig = new AppInfo();
	}

	public void init()
	{
		McLog.m(this, "init");
	}

	public void unInit()
	{
		McLog.m(this, "unInit");
	}

	public AppInfo getAppConfig()
	{
		return appConfig;
	}

	public void clearAllBitmap()
	{
		File imagFile = new File(Globals.APP_FILE_IMAGE_PATH);
		if (imagFile.exists() && imagFile.isDirectory())
		{
			deleteSub(imagFile);
		}
		imagFile = new File(Globals.APP_FILE_CACHE_PATH);
		if (imagFile.exists() && imagFile.isDirectory())
		{
			deleteSub(imagFile);
		}
		ImageCacheManager mImageCacheManager = ImageCacheManager.getCacheManager(AppContext.getInstance(), Globals.SHENOHUOTONG_MODE, Globals.SHENOHUOTONG_TAG);
		mImageCacheManager.clearCache();
	}

	void deleteSub(File subFile)
	{
		File[] files = subFile.listFiles();
		for (File f : files)
		{
			f.delete();
		}
	}
}